package com.xbongbong.saas.enums.base;

import com.xbongbong.paas.enums.SheetTypeEnum;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.saas.constant.PaymentConstant;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 回款单字段attr基础枚举
 * 如果非经销商、经销商类模板都有的字段，则需在该基础枚举内维护attr
 * @author zcp
 */
@Getter
public enum PaymentSheetBaseEnum {
    /**
     * 基本信息
     */
    BASE_INFO("other_1"),
    SHEET_NO("serialNo"),
    //回、付款单字段attr都统一用PaymentConstant.ATTR_SHEET_TYPE，即 text_10
    PAYMENT_SHEET_TYPE(PaymentConstant.ATTR_SHEET_TYPE),
    CUSTOMER_ID("text_6"),
    CONTRACT("text_4"),
    PAYMENT("text_5"),
    AMOUNT("num_1"),
    WRITE_OFF_AMOUNT("num_7"),
    INVOICE_AMOUNT("num_8"),
    BELONG_ID("array_1"),
    PAYMENT_TIME("date_1"),
    FUND_ACCOUNT("text_14"),
    PAY_METHOD("text_3"),

    SYSTEM_INFO("other_2"),
    PAYMENT_TASK("text_81"),
    //当前该字段只有经销商模板在使用
    ONLINE_PAYMENT_FLOW("text_83"),
    //支付人，long类型是系统预留，总计10个，不会开放给用户
    PAYER_ID("long_1"),
    //付款人名称
    PAYER("text_85"),

    MEMO("text_7"),
    FILE("file_1"),
    RED_SHEET("text_16"),

    CREATOR_ID("creatorId"),
    ADD_TIME("addTime"),
    UPDATE_TIME("updateTime"),

    OWNER_ID("ownerId"),
    COUSERID("coUserId"),
    SYS_LONG_10("sysLong10"),

    CUSTOMER_NAME_LINK_TEXT("text_11"),
    CONTRACT_LINK_TEXT("text_12"),
    PAYMENT_LINK_TEXT("text_13"),
    FUND_ACCOUNT_LINK_TEXT("text_15"),
    RED_SHEET_LINK_TEXT("text_17"),
    PAYMENT_TASK_LINK_TEXT("text_82"),
    ONLINE_PAYMENT_FLOW_LINK_TEXT("text_84"),
    ;

    private final String attr;

    PaymentSheetBaseEnum(String attr) {
        this.attr = attr;
    }
    /**
     * 把传入的字段（类型为LINK_BUSINESS_SINGLE）的转为其隐藏字段
     * @param attr 字段名
     * @return java.lang.String
     * @author zcp
     * @date 2019/7/4 15:31
     * @since v1.0
     * @version v1.0
     */
    public static String changeToHide4Link(String attr) {
        if (Objects.equals(attr, CUSTOMER_ID.attr)) {
            return CUSTOMER_NAME_LINK_TEXT.attr;
        } else if (Objects.equals(attr, CONTRACT.attr)) {
            return CONTRACT_LINK_TEXT.attr;
        } else if (Objects.equals(attr, PAYMENT.attr)) {
            return PAYMENT_LINK_TEXT.attr;
        } else if (Objects.equals(attr, PAYMENT_TASK.attr)) {
            return PAYMENT_TASK_LINK_TEXT.attr;
        } else if (Objects.equals(attr, ONLINE_PAYMENT_FLOW.attr)) {
            return ONLINE_PAYMENT_FLOW_LINK_TEXT.attr;
        }
        return attr;
    }

    /**
     * 审批流程内不可编辑，必可见字段
     * @param distributorMark
     * @return java.util.List<java.lang.String>
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static List<String> processNoneEditMustShow(Integer distributorMark){
        if (Objects.equals(distributorMark, DistributorMarkEnum.DISTRIBUTOR.getCode())) {
            return Arrays.asList(PAYMENT_SHEET_TYPE.attr, CUSTOMER_ID.attr, CUSTOMER_NAME_LINK_TEXT.attr, CONTRACT.attr, CONTRACT_LINK_TEXT.attr, PAYMENT.attr, PAYMENT_LINK_TEXT.attr, AMOUNT.attr, WRITE_OFF_AMOUNT.attr, BELONG_ID.attr, PAY_METHOD.attr, FILE.attr, PAYER_ID.attr, PAYER.attr, ONLINE_PAYMENT_FLOW.attr, ONLINE_PAYMENT_FLOW_LINK_TEXT.attr);
        } else {
            return Arrays.asList(PAYMENT_SHEET_TYPE.attr, CUSTOMER_ID.attr, CUSTOMER_NAME_LINK_TEXT.attr, CONTRACT.attr, CONTRACT_LINK_TEXT.attr, PAYMENT.attr, PAYMENT_LINK_TEXT.attr, AMOUNT.attr, WRITE_OFF_AMOUNT.attr, BELONG_ID.attr);
        }
    }

    /**
     * 得到新建or编辑时各种回款单禁止修改的字段
     * 具体见文档：https://xbb.yuque.com/lfwuxq/vsf9sv/tisg7y#qj7I8
     * @param addUnableEdit true 新增是禁止编辑，false 编辑时各类型回款单不能编辑的字段
     * @param sheetTypeEnum 回款单类型
     * @param distributorMark 经销商mark标识
     * @return java.util.List<java.lang.String>
     * @author zcp
     * @date 19/11/18 018 21:00
     * @update 19/11/18 018 21:00
     * @since v1.0
     * @version v1.0
     */
    public static List<String> getUnableEditAttrList(boolean addUnableEdit, SheetTypeEnum sheetTypeEnum, Integer distributorMark) {
        List<String> unableEditAttrList = new ArrayList<>();
        unableEditAttrList.add(PAYMENT_SHEET_TYPE.attr);
        if (Objects.equals(distributorMark, DistributorMarkEnum.DISTRIBUTOR.getCode())) {
            //经销商的，则以下字段不管新建还是编辑时，都不允许操作
            unableEditAttrList.add(PAY_METHOD.attr);
            unableEditAttrList.add(PAYER_ID.attr);
            unableEditAttrList.add(PAYER.attr);
            unableEditAttrList.add(ONLINE_PAYMENT_FLOW.attr);
            unableEditAttrList.add(ONLINE_PAYMENT_FLOW_LINK_TEXT.attr);
        }
        if (addUnableEdit) {
            unableEditAttrList.add(PAYMENT.attr);
            unableEditAttrList.add(PAYMENT_LINK_TEXT.attr);
            //新增时各类型回款单不能编辑的字段
            switch (sheetTypeEnum) {
                case RED_WRITE_OFF:
                case RED_WRITE_OFF_PREPAYMENT:
                case RED_WRITE_OFF_BALANCE:
                case RED_PREPAYMENT:
                    unableEditAttrList.add(RED_SHEET.attr);
                    unableEditAttrList.add(RED_SHEET_LINK_TEXT.attr);
                    unableEditAttrList.add(CUSTOMER_ID.attr);
                    unableEditAttrList.add(CUSTOMER_NAME_LINK_TEXT.attr);
                    unableEditAttrList.add(CONTRACT.attr);
                    unableEditAttrList.add(CONTRACT_LINK_TEXT.attr);
                    return unableEditAttrList;
                case BAD_PAYMENT:
                    unableEditAttrList.add(AMOUNT.attr);
                    return unableEditAttrList;
                default:
                    return unableEditAttrList;
            }
        } else {
            unableEditAttrList.add(PAY_METHOD.attr);
            unableEditAttrList.add(SHEET_NO.attr);
            unableEditAttrList.add(CUSTOMER_ID.attr);
            unableEditAttrList.add(CUSTOMER_NAME_LINK_TEXT.attr);
            unableEditAttrList.add(CONTRACT.attr);
            unableEditAttrList.add(CONTRACT_LINK_TEXT.attr);
            unableEditAttrList.add(PAYMENT.attr);
            unableEditAttrList.add(PAYMENT_LINK_TEXT.attr);
            unableEditAttrList.add(AMOUNT.attr);
            unableEditAttrList.add(WRITE_OFF_AMOUNT.attr);
            unableEditAttrList.add(BELONG_ID.attr);
            unableEditAttrList.add(PAYMENT_TIME.attr);
            unableEditAttrList.add(FUND_ACCOUNT.attr);
            unableEditAttrList.add(PAYMENT_TASK.attr);
            unableEditAttrList.add(PAYMENT_TASK_LINK_TEXT.attr);
            //再加上红冲的，关联原始单据
            unableEditAttrList.add(RED_SHEET.attr);
            unableEditAttrList.add(RED_SHEET_LINK_TEXT.attr);
            //负责人、协同人字段
            unableEditAttrList.add(OWNER_ID.attr);
            unableEditAttrList.add(COUSERID.attr);
            return unableEditAttrList;
        }
    }
}
